<!--
 * @Description: 
 * @Author:  huangshuai
 * @Date: 2023-10-20 15:07:34
 * @LastEditTime: 2023-12-27 14:59:29
 * @LastEditors: huangshuai 
-->
<template>
  <div class="report-others" v-loading="loading">
    <el-table :data="tableData" stripe style="width: 95%" border>
      <el-table-column
        prop="content"
        label="内容"
        show-overflow-tooltip
        width="180"
        align="center"
      />

      <el-table-column align="center" label="分类" width="180">
        <template #default="scope">
          <span v-if="scope.row.reportCategory === '0'"> 宠物方面</span>

          <span v-else-if="scope.row.reportCategory === '1'">住户方面</span>
          <span v-else-if="scope.row.reportCategory === '2'"
            >社区管理人方面</span
          >
          <span v-else-if="scope.row.reportCategory === '3'">其他方面</span>
        </template>
      </el-table-column>
      <el-table-column prop="createTime" align="center" label="创建时间" />
      <el-table-column prop="updateTime" align="center" label="审核时间" />
      <el-table-column align="center" prop="examineStatus" label="审核状态">
        <template #default="scope">
          <el-button size="small" v-if="scope.row.examineStatus === 0">
            未处理
          </el-button>
          <el-button
            size="small"
            type="primary"
            v-else-if="scope.row.examineStatus === 1"
          >
            正在处理
          </el-button>
          <el-button
            size="small"
            type="success"
            v-else-if="scope.row.examineStatus === 2"
          >
            处理通过
          </el-button>
          <el-button size="small" v-else> 无 </el-button>
        </template>
      </el-table-column>
      <el-table-column align="center">
        <template #header>
          <el-button @click="handleReport" type="primary">点击举报</el-button>
        </template>
        <template #default="scope">
          <el-button size="small" @click="handleLook(scope.row)"
            >查看举报内容</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <div class="pagination">
      <el-pagination
        v-model:current-page="currentPage"
        v-model:page-size="pageSize"
        :page-sizes="[10, 15, 20, 2]"
        :small="true"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      >
      </el-pagination>
    </div>
  </div>
  <contextDialog ref="contextDialogRef" />
</template>

<script setup lang="ts">
import { onMounted, ref } from "vue";
import { useRouter } from "vue-router";
import { listReportInfoByUserId } from "@/api/owner";
import contextDialog from "./context-dialog.vue";
const contextDialogRef = ref();
const router = useRouter();

const tableData = ref([]);
//查看
const handleLook = (data: any) => {
  contextDialogRef.value.showDialog(data);
};

//分页--start
const currentPage = ref(1);
const pageSize = ref(10);
const total = ref(0);
const handleSizeChange = () => {
  getData();
};
const handleCurrentChange = () => {
  getData();
};
//分页--end

//点击举报
const handleReport = () => {
  router.push("/owner/report");
};

/********************* */
//------------api---------
/********************* */
const loading = ref<boolean>(false);
const getData = async () => {
  loading.value = true;
  await listReportInfoByUserId(currentPage.value, pageSize.value).then(
    (res: any) => {
      tableData.value = res.data;
      total.value = +res.total;
    }
  );
  loading.value = false;
};
onMounted(() => {
  getData();
});
</script>

<style scoped lang="less">
.report-others {
  width: 100%;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  padding-top: 10px;
  :deep(.el-popper) {
    display: none;
  }
}
.pagination {
  width: 95%;
  margin-top: 10px;
  display: flex;
  justify-content: space-between;
}
</style>
